#include "shape3.h"

namespace Tetris{

Shape3::Shape3() : Shape() {
	//  0000     
	//  0#00
	//  0#00
	//  0##0
	this->state = MyRand::Instance()->Next();
	this->Transform();
}

void Shape3::changeToState0(){
	this->Clear();
	this->p_arr[5] = true;
	this->p_arr[9] = true;
	this->p_arr[13] = true;
	this->p_arr[14] = true;
}

void Shape3::changeToState1(){
	this->Clear();
	this->p_arr[8] = true;
	this->p_arr[9] = true;
	this->p_arr[10] = true;
	this->p_arr[12] = true;
}

void Shape3::changeToState2(){
	this->Clear();
	this->p_arr[4] = true;
	this->p_arr[5] = true;
	this->p_arr[9] = true;
	this->p_arr[13] = true;
}

void Shape3::changeToState3(){
	this->Clear();
	this->p_arr[6] = true;
	this->p_arr[8] = true;
	this->p_arr[9] = true;
	this->p_arr[10] = true;
}

void Shape3::Transform(){
	this->state ++;
	this->state = this->state % 4;
	if(this->state == 0)
		this->changeToState0();
	else if(this->state == 1)
		this->changeToState1();
	else if(this->state == 2)
		this->changeToState2();
	else
		this->changeToState3();
}

Shape* Shape3::Clone() const{
	Shape3* p = new Shape3();
	p->state = this->state;
	p->row = this->row;
	p->col = this->col;
	int len = p->row * p->col;
	for(int i=0;i<len;++i)
		p->p_arr[i] = this->p_arr[i];
	return p;
}

void Shape3::Restore(const Shape* p_shape){
	const Shape3* p = dynamic_cast<const Shape3*>(p_shape);
	this->state = p->state;
	this->row = p->row;
	this->col = p->col;
	int len = this->row * this->col;
	for(int i=0;i<len;++i)
		this->p_arr[i] = p->p_arr[i];
}

}